package com.xiaomitest;

import java.util.Scanner;

// 树的高度
public class TreeHeight {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] treeNode = new int[n];
        for (int i = 0; i < n - 1; i++) {
            int father = sc.nextInt();
            int child = sc.nextInt();
            treeNode[child] = father;
        }
        int height = 1;
        for (int i = 0; i < n ; i++) {
            int subHeight = getSubHeight(i,treeNode);
            height = Math.max(height,subHeight);
        }
        System.out.println(height);

    }

    private static int getSubHeight(int child,int[] treeNode){
        int height = 1;
        while (treeNode[child] != child){
            int temp = treeNode[child];
            child = temp;
            height++;
        }
        return height;
    }
}

/*
* import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        int n = in.nextInt();
        if(n<3){
            System.out.println(n);
        }
        else{
            int[] height = new int [n];
            int[] binary = new int[n];
            height[0] = 1;
            int max = 0;
            for(int i = 0;i<n-1;i++){
                int parent = in.nextInt();
                int child = in.nextInt();
                binary[parent] += 1;
                if(binary[parent] < 3){
                    height[child] = height[parent]+1;
                }
                max = Math.max(max, height[child]);
            }
            System.out.println(max);
        }
    }
}

* */